package pro.softzhang.algo.lc400;

/**
 *
 */
public class LC443_StringCompression {
    public static void main(String[] args) {

    }

    static class Solution {
        public int compress(char[] chars) {
            int write = 0;
            for(int i = 0; i < chars.length;){
                int j = i;
                while(j < chars.length && chars[i] == chars[j])
                    j++;
                chars[write++] = chars[i];
                if(j - i > 1){
                    String tmp = Integer.toString(j - i);
                    for(int k = 0; k < tmp.length();k++)
                        chars[write++] = tmp.charAt(k);
                }
                i = j;
            }
            return write;
        }
    }
}
